var pass = /(.+){6,16}$/; //'密码必须6到16位'
var positive_number = /^\d+(?=\.{0,1}\d+$|$)/; //'正数'
var int_number = /^-?[1-9]\d*$/; //'正整数'
var phone_test = /^1[3456789]\d{9}$/ //手机号


/**
 * 判断 空 、undefined
 * @param str
 * @returns {boolean}
 */
function isEmpty(data) {
    if (data == undefined || data == null) return true;
    var s = data.toString().trim()
    return s.length == 0;
}

/**
 * layui  确认框
 * */
function confirm(msg, success) {
    layer.confirm("<div style='text-align: center'>" + msg + "</div>",
        {btnAlign: "c", offset: 250}, function (i) {
            success()
            layer.close(i)
        })
}

/**
 * layui 加载层
 */
function load() {
    return layer.load(0, {shade: [0.1, '#000']});
}

/**
 * 取消按钮
 */
function hideFun() {
    layer.closeAll();
}

/**
 * layui 数据表格
 */
function renderTable(elem, url, data, where) {
    var loadingIndex = load();
    var table =
        {
            elem: elem,
            url: url,
            cellMinWidth: 0,
            page: true,
            cols: [
                data
            ],
            request: {
                pageName: 'current',
                limitName: 'size'
            },
            where: where,
            response: {statusCode: 1},
            parseData: function (res) {
                if (res.code == 1)
                    return {
                        "code": res.code,
                        "msg": res.message,
                        "count": res.data.total,
                        "data": res.data.records
                    }
                else
                    return {
                        "code": 0,
                        "msg": "没有找到相关数据",
                        "count": 0,
                        "data": {}
                    }
            },
            done: function () {
                layer.close(loadingIndex);
            }
        }
    return table
}


/**
 * get ajax 请求
 */
function getAjaxReq(url, data, success) {
    var i = load();
    ajaxReq(url, "GET", data, false, false, function () {
    }, success, function () {
        layer.msg("请求接口异常")
    }, function () {
        layer.close(i)
    })
}

/**
 * get ajax 请求
 */
function getAjaxReq1(url, data, success) {
    ajaxReq(url, "GET", data,
        false, false,
        function () {
        },
        success,
        function () {
        },
        function () {
        }
    )
}

/**
 * post ajax 请求
 */
function postAjaxReq(url, data, success) {
    var i = load();
    ajaxReq(url, "POST", data, false, false, function () {
    }, success, function () {
        layer.msg("请求接口异常")
    }, function () {
        layer.close(i)
    })
}

function postAjaxReqLogin(url, data, success) {
    // var index = layer.load(2, {
    //     shade: [0.1,'#fff'] //0.1透明度的白色背景
    // });
    ajaxReq(url, "POST", data, false, false, function () {
    }, success, function () {
        layer.msg("请求接口异常")
    }, function () {
        layer.close(i)
    })
}

/**
 * 数组 ajax 请求
 */
function arrayAjaxReq(url, data, success) {
    var i = load();
    ajaxReq(url, "POST", data, true, false, function () {
    }, success, function () {
        layer.msg("请求接口异常")
    }, function () {
        layer.close(i)
    })
}

/**
 * 日期格式化
 */
Date.prototype.format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1,                 //月份
        "d+": this.getDate(),                    //日
        "h+": this.getHours(),                   //小时
        "m+": this.getMinutes(),                 //分
        "s+": this.getSeconds(),                 //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds()             //毫秒
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
}
Date.prototype.plusDate = function (days) {
    var date = this.valueOf();
    date = date + days * 24 * 60 * 60 * 1000;
    date = new Date(date);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    var d = date.getDate();
    if (m <= 9) m = "0" + m;
    if (d <= 9) d = "0" + d;
    var result = y + "-" + m + "-" + d;
    return result;
}


/**
 * json  ajax 请求
 */
function jsonAjaxReq(url, data, success) {
    var i = load();
    ajaxReq(url, "POST", JSON.stringify(data), false, true, function () {
    }, success, function () {
        layer.msg("请求接口异常")
    }, function () {
        layer.close(i)
    })
}

function ajaxReq(url, type, data, isArray, isJson, before, success, fail, complete) {
    var ajaxContent = {
        url: url,
        type: type,
        data: data,
        dataType: "json",
        beforeSend: function () {
            before()
        },
        success: function (res) {
            success(res)
        },
        fail: function () {
            layer.closeAll()
            fail()
        },
        complete: function () {
            complete()
        }
    }
    if (isArray)
        ajaxContent["traditional"] = true
    if (isJson)
        ajaxContent["contentType"] = "application/json"
    $.ajax(ajaxContent)
}
/**
 * 数据状态
 */
function msgStatusSet(msgStatus) {
    if(status==1){
        msgStatus ="未激活"
    }else {
        msgStatus ="激活"
    }
    return msgStatus;
}
function serverStatusSet(serverStatus) {
    if(serverStatus==0){
        serverStatus ="未到期"
    }else if(serverStatus==1){
        serverStatus ="已到期"
    }else if(serverStatus==2){
        serverStatus ="即将到期"
    }else if(serverStatus==3){
        serverStatus ="试用期"
    }else{
        serverStatus ="未知"
    }
    return serverStatus;
}
function oweStatusSet(oweStatus) {
    if(oweStatus==0){
        oweStatus = "欠费"
    }else {
        oweStatus = "未欠费"
    }
    return oweStatus;
}
function switchStatusSet(switchStatus) {

    if(switchStatus==0){
        switchStatus = "拉闸"
    }else {
        switchStatus = "不拉闸"
    }
    return switchStatus;
}
function payTypeSet(payType) {
    if(payType==3){
        payType = "季服务费"
    }else if(payType==6){
        payType = "半年服务费"
    }else if(payType==12){
        payType = "年服务费"
    }
    return payType;
}
/**
 * 高度
 */
var heightClient  = document.documentElement.clientHeight ||  document.body.clientHeight;